package br.indt.framework.ui.common;

import javax.microedition.lcdui.Graphics;

public class Separator extends Widget {

	private static final int SEP_SIZE = 2;
	
	private boolean vertical = false;
	private int highlightColor = Color.WHITE;
	
	public Separator(String name) {
		super(name);		
		this.backgroundColor = Color.LIGHT_GRAY;
	}
	
	public Separator(String name, boolean vertical) {
		super(name);
		this.vertical = vertical;
		this.backgroundColor = Color.LIGHT_GRAY;
	}
	
	public boolean isVertical() {
		return vertical;
	}

	public int getHighlightColor() {
		return highlightColor;
	}

	public void setHighlightColor(int highlightColor) {
		this.highlightColor = highlightColor;
	}

	public void setWidth(int width) {
		if (vertical) {
			this.width = SEP_SIZE + leftMargin + rightMargin;
		} else {
			super.setWidth(width);
			this.height = SEP_SIZE + topMargin + bottomMargin;
		}
	}
	
	public void setHeight(int height) {
		if (vertical) {
			super.setHeight(height);
			this.width = SEP_SIZE + leftMargin + rightMargin;
		} else {
			this.height = SEP_SIZE + topMargin + bottomMargin;
		}
	}
	
	public void setMargin(int left, int top, int right, int bottom) {
		super.setMargin(left, top, right, bottom);
		if (vertical) {
			this.width = SEP_SIZE + leftMargin + rightMargin;
		} else {
			this.height = SEP_SIZE + topMargin + bottomMargin;
		}
	}
	
	protected void paint(Graphics g, int x, int y, int maxWidth, int maxHeight) {
		
		g.setClip(x + leftMargin, y + topMargin, width - rightMargin - leftMargin, height - bottomMargin - topMargin);
		
		x += leftMargin;
		y += topMargin;
		
		if (backgroundColor != Color.TRANSPARENT) {
			g.setColor(backgroundColor);
			if (vertical) {
				g.drawLine(x, y, x, y + height - topMargin - bottomMargin);
			} else {
				g.drawLine(x, y, x + width - leftMargin - rightMargin, y);
			}
		}
		
		if (highlightColor != Color.TRANSPARENT) {
			g.setColor(highlightColor);		
			if (vertical) {
				g.drawLine(x + 1, y, x + 1, y + height - topMargin - bottomMargin);
			} else {
				g.drawLine(x, y + 1, x + width - leftMargin - rightMargin, y + 1);
			}
		}
	}

	public void pressFire() {
	}
}
